<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>规则制度类型</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
</head>
<script>
    $.ajaxSetup({
        async: false
    });
    $(function () {
        $(".layui-bg-red").click(function () {
            $("#tsone").html("");
            $("#tstwo").html("");
        });
        //图片1
        $("#btnone").click(function () {
            $("#fileOne").click();
            $("#fileOne").change(function (obj) {
                var fileInput = $('#fileOne').get(0).files[0];//获取input控件的file
                if (fileInput) {
                    var str = fileInput.name;
                    //取后缀名
                    $("#tsone").html(str.substring(0, 4) + "..." + str.match(/\.([^\.]+)$/)[1]);
                }
            });
        });
    })
</script>
<form class="layui-form layui-form-pane" id="formDId" action="">
    <input type="hidden" name="pkRegimeTypeId" id="pkRegimeTypeId"/>


    <div class="layui-form-item">
        <label class="layui-form-label">上级类型</label>
        <div class="layui-input-block">
            <div id="regimeTypeSuperior" class="xm-select-demo"></div>
        </div>
        <span id="msg">不选则为一级菜单</span>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"style="width: 150px;">规则制度类型名称</label>
        <div class="layui-input-block"style="margin-left: 150px">
            <input type="text" name="regimeTypeName" id="regimeTypeName" autocomplete="off" placeholder="请输入规则制度类型名称"
                   class="layui-input" lay-verify="required">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">提交</button>
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="取消">
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'laydate', 'upload'], function () {
        var form = layui.form
            , laydate = layui.laydate
            , upload = layui.upload;
        //只出现确定按钮
        laydate.render({
            elem: '#createdTime'
            , btns: ['confirm']
        });//只出现确定按钮
        laydate.render({
            elem: '#updatedTime'
            , btns: ['confirm']
        });

        //需要操作的数据
        let pkRegimeTypeId = getQueryString("pkRegimeTypeId");
        //判断是否是查看
        let show = getQueryString("show");
        layui.use(['form', 'laydate', 'table'], function () {
            var table = layui.table
                , form = layui.form
                , layer = layui.layer;

            //加载组件
            layui.config({
                //引入扩展文件库
                base: getRootPath() + 'res/layui/dist/'
            }).extend({
                //引入对应的文件名
                xmSelect: 'xm-select'
                //拿到对应的文件模块
            }).use(['xmSelect'], function () {
                //对于模块赋值使用
                var xmSelect = layui.xmSelect;
                //渲染多选
                pkJurisdictionId = xmSelect.render({
                    el: '#regimeTypeSuperior',
                    radio: true,
                    name:'regimgTypeSuperior',
                    layVerify: 'required',
                    tree: {
                        show: true,
                        strict: false,
                        expandedKeys: [-1],
                    },
                    height: 'auto',
                    data: loadOaRegimeType(pkRegimeTypeId, show)
                })

            });

            function loadOaRegimeType(id, show) {
                let url = getRootPath() + "OaRegimeTypeAction/loadOaRegimeType";
                let data = {
                    id: id, //需要操作的数据
                    show: show // 判断是否是查看
                };
                let res = getAjax(url, data);
                if (res) {
                    return res;
                } else {
                    return [];
                }

            }


            let res;
            console.info(pkRegimeTypeId);
            console.info(show);
            if (pkRegimeTypeId) {
                res = getAjaxById(getRootPath() + "OaRegimeTypeAction/findById/" + pkRegimeTypeId);
                //客户类型id
                $("#pkRegimeTypeId").val(res.data.pkRegimeTypeId);
                //客户类型
                let regimeTypeName = $("#regimeTypeName");
                regimeTypeName.val(res.data.regimeTypeName);

                //判断是否是查看
                if (show) {
                    //工作总结类型
                    formDisabled($("#pkRegimeTypeId"));
                    //本阶段总结
                    formDisabled(clientTypeName);
                    formDisabled($("#regimeTypeSuperior"));
                    console.info("隐藏按钮")
                    //隐藏提交按钮
                    $("#sub").hide();

                }
                form.render();
            }
            form.render();

            //监听起草提交
            form.on('submit(demo1)', function (data) {

                console.info(data.field);
                // 单击之后提交按钮不可选,防止重复提交
                var DISABLED = 'layui-btn-disabled';
                // 增加样式
                $('.site-demo-active').addClass(DISABLED);
                // 增加属性
                $('.site-demo-active').attr('disabled', 'disabled');
                let res = postAjax(getRootPath() + "OaRegimeTypeAction/updateOrAdd", data.field);
                console.info(res);
                if (res.code === 1) {
                    layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                    setTimeout(function () {
                        formClose();
                    }, 3000);
                    setTimeout(function () {
                        parent.layui.table.reload('test');//刷新父页面
                        //window.parent.location.reload();//刷新父页面
                        const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    }, 3000);
                    //window.location.reload();//刷新页面
                } else if (res.code === 500) {
                    error('500');
                } else {
                    layer.msg("新增失败");
                }
                return false;
            });

            $("#demo3").on("click", function () {
                //询问框
                layer.confirm('是否关闭该页面？', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    formClose();
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                });
            });

            if (pkRegimeTypeId) {
                findById();
            }
        });

        /**
         * 禁用
         *  @param forms 控件
         */
        function formDisabled(forms) {
            const DISABLED = 'layui-btn-disabled';
            forms.attr('disabled', 'disabled');
            forms.addClass(DISABLED);
        }

        function findById() {
            var id = getQueryString("pkRegimeTypeId");
            var url = getRootPath() + "OaRegimeTypeAction/findById/" + id;
            var data = getAjaxById(url);
            $("#pkRegimeTypeId").val(data.data.pkRegimeTypeId);
            $("#regimeTypeName").val(data.data.regimeTypeName);
            console.info(data)
        }

    });
</script>
</body>
</html>